package xuegao.study.mall.admin.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xuegao.study.mall.admin.feign.OmsOrderReturnReasonClient;
import xuegao.study.mall.common.api.CommonPage;
import xuegao.study.mall.common.api.CommonResult;
import xuegao.study.mall.common.model.oms.OmsOrderReturnReason;

import java.util.List;

@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {

    @Autowired
    private OmsOrderReturnReasonClient omsOrderReturnReasonClient;

    @ApiOperation("添加退货原因")
    @PostMapping(value = "/create")
    public CommonResult create(@RequestBody OmsOrderReturnReason returnReason) {
        return omsOrderReturnReasonClient.create(returnReason);
    }

    @ApiOperation("修改退货原因")
    @PostMapping(value = "/update/{id}")
    public CommonResult update(@PathVariable Long id, @RequestBody OmsOrderReturnReason returnReason) {
        return omsOrderReturnReasonClient.update(id, returnReason);
    }

    @ApiOperation("批量删除退货原因")
    @PostMapping(value = "/delete")
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {
        return omsOrderReturnReasonClient.delete(ids);
    }

    @ApiOperation("分页查询退货原因")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<OmsOrderReturnReason>> list(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return omsOrderReturnReasonClient.list(pageSize, pageNum);
    }

    @ApiOperation("获取单个退货原因详情")
    @GetMapping(value = "/{id}")
    public CommonResult<OmsOrderReturnReason> getItem(@PathVariable Long id) {
        return omsOrderReturnReasonClient.getItem(id);
    }

    @ApiOperation("修改退货原因启动状态")
    @PostMapping(value = "/update/status")
    public CommonResult updateStatus(@RequestParam(value = "status") Integer status,
                                     @RequestParam("ids") List<Long> ids) {
        return omsOrderReturnReasonClient.updateStatus(status, ids);
    }
}
